<template>
  <div class="layout-container">
    <el-container>
      <el-header class="header">
        <div class="bb">品优购电商后台</div>
        <el-button @click="logout">退出登录</el-button>
      </el-header>
      <el-container>
        <el-aside :width="collapse ? '60px' : '200px'" class="aside">
          <el-menu
            @close="handleClose"
            @open="handleOpen"
            active-text-color="hotpink"
            background-color=" #313a46"
            class="el-menu-vertical-demo"
            :default-active="$route.path"
            :router="true"
            text-color="#fff"
          >
            <el-menu-item>
              <i @click="collapse = !collapse" class="el-icon-menu"></i>
            </el-menu-item>
            <el-submenu
              :index="index + ''"
              v-for="(item, index) in list"
              :key="item.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group v-for="item in item.children" :key="item.id">
                <el-menu-item :index="'/' + item.path">{{
                  item.authName
                }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { listApi } from '@/api/user'
export default {
  name: 'layout',
  data () {
    return {
      collapse: false,
      list: []
    }
  },
  async created () {
    const res = await listApi()
    // console.log(res, 888888)
    this.list = res.data
  },
  computed: {
  },
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath);
    },
    logout () {
      //干掉token 然后 回 login 
      this.$store.commit('user/resetToken')
      this.$router.push('/login')
    }
  }
}
</script>
<style lang='scss'  scoped>
.layout-container {
  height: 100vh;
  overflow: hidden;

  .header {
    background-color: #313a46;
    display: flex;
    .bb {
      font-size: 26px;
      width: 100%;
      text-align: center;
      line-height: 80px;
      height: 80px;
      color: #fff;
      font-weight: 700;
    }
  }

  .el-container {
    height: 100vh;
    overflow: auto;

    .el-aside {
      background-color: #313a46;
    }
  }
}
</style>

